package org.baseflexcharts.databoard
{
	import mx.collections.ArrayCollection;
	
	import org.baseflexcharts.shapes.Rectangle;
	
	public class YOnlyBarDataBoard extends BaseDataBoard
	{								
		private var _barWidth:Number = 0;
		
		public function YOnlyBarDataBoard()
		{
			super()
		}
		
		public override function draw():void
		{
			this.removeAllChildren();
			
			if (xAmount > 0 && yAmount > 0 && this.dataProvider != null)
			{
				var unitWidth:uint = (this.width - leftMargin - rightMargin) / (xAmount - 1);
				var unitHeight:uint = (this.height - topMargin - bottomMargin) / (yAmount - 1);
				var remainHeight:uint = (this.height - topMargin - bottomMargin) % (yAmount - 1);				

				if (dataProvider != null) {
				
					for (var i:uint = 0; i < dataProvider.length; i++)
					{
						var object:Object = dataProvider.getItemAt(i);
						
						var value:uint = uint(object.value);

						var tempX:uint = leftMargin + i * unitWidth;
						var tempY:uint = topMargin + remainHeight + unitHeight * (yAmount - 1 - value / yUnitValue);
					    
					    if (barWidth == 0) 
					    {
					    	barWidth = unitWidth / 4;
					    }
					    
					    var barHeight:Number = unitHeight * (value / yUnitValue);					    
					    
					    var bar:Rectangle = new Rectangle(barWidth, barHeight, lineColor, object.tip);
					    
					    bar.x = tempX + xOffset;
					    bar.y = tempY;
					    
					    this.addChildAt(bar, 0);
					}
				
				}
			}
		}
		
		public function get barWidth():Number
		{
			return this._barWidth;
		}
		
		public function set barWidth(data:Number):void
		{
			this._barWidth = data;
		}

	}
}